package tidb

import (
	"fmt"
	"github.com/pingcap/tidb/pkg/parser"
	"github.com/pingcap/tidb/pkg/parser/ast"
	_ "github.com/pingcap/tidb/pkg/parser/test_driver"
)

func TidbParser() {
	p := parser.New()

	stmtNodes, _, err := p.Parse("SELECT * FROM table1 WHERE id = 1", "", "")
	if err != nil {
		fmt.Println("Parse failed:", err)
		return
	}

	for _, stmt := range stmtNodes {
		stmt.Accept(&Visitor{})
	}
}

type Visitor struct {
}

func (v *Visitor) Enter(n ast.Node) (node ast.Node, skipChildren bool) {
	fmt.Printf("Node type: %T,%+v,isnil=%v \n", n, n, nil == n)
	//reflect.TypeOf(n)

	return n, false
}

func (v *Visitor) Leave(n ast.Node) (node ast.Node, ok bool) {
	return n, true
}
